<?php
namespace Home\Controller;

class GuideController extends CommonController{
    
    private $guide_data = array();
    
	public function index(){
	    
	    $this->display();
    }
    
    public function setProgress() {
        $this->assign('types',C('TYPES'));
        $this->display();
    }
    
    public function chgProgress(){
        
        $this->display();
    }
    
    public function saveGuideData(){
        $data = session('guide_data');
        $data = $data ? $data : array();
        $post_data = I('post.');
        foreach ($post_data as $key=>$val){
            $data[$key] = $val;
        }
        session('guide_data',$data);
        $this->success($data);
    }
    
    public function getCtypes() {
        $key = I('post.key');
        $types = C('TYPES');
        $data = session('guide_data');
        $data = $data ? $data : array();
        $data['type'] = I('post.name');
        session('guide_data',$data);
        $this->success($types[$key]['children']);
    }
    
    public function memberSetData() {
        $datas = I('post.');
        $guide_data = session('guide_data');
        foreach ($datas as $key=>$val){
            if($key == 'permit')continue;
            $guide_data[$key] = $val;
        }
        session('guide_data',$guide_data);
        $preview_data = array();
        $preview_data['goods_type'] = $guide_data['type'];
        switch ($guide_data['selectaddr']){
            case '0':$preview_data['address_type'] = '（未选择）';break;
            case '1':$preview_data['address_type'] = '提供地址';break;
            case '3':$preview_data['address_type'] = '自有地址';break;
        }
        $preview_data['ouraddr'] = $guide_data['ouraddr'];
        $preview_data['selectaddr'] = $guide_data['type'];
        $preview_data['type'] = $guide_data['type'];
        $preview_data['typescope'] = implode('、', $guide_data['typescope']);
        $preview_data['typeperson'] = $guide_data['typeperson'];
        switch ($preview_data['typeperson']) {
            case '个人投资':$preview_data['person_num'] = $guide_data['investor']=='1'?'一位国内个人':'两位及以上国内个人';
                         $preview_data['ziben'] = $guide_data['investormon'];
                         $preview_data['zonge'] = $guide_data['investornum'];break;
            case '企业投资':$preview_data['person_num'] = $guide_data['firm']=='1'?'一家国内企业':'两家及以上国内企业';
                         $preview_data['ziben'] = $guide_data['firmmon'];
                         $preview_data['zonge'] = $guide_data['firmnum'];break;
            case '国内合资':$preview_data['person_num'] = $guide_data['gfirmpnum']=='1'?'一位国内个人':'两位及以上国内个人';
                         $preview_data['company_num'] = $guide_data['gfirmfnum']=='1'?'一家国内企业':'两家及以上国内企业';
                         $preview_data['ziben'] = $guide_data['gfirmmon'];
                         $preview_data['zonge'] = $guide_data['gfirmnum'];
        }
        $preview_data['typeboard'] = $guide_data['typeboard'];
        $permits = array();
        $goodsModel = D('Goods');
        foreach ($datas['permit'] as $val){
            $permits[] = D('Goods')->where(array('goods_id'=>$val))->getField('goods_name');
        }
        $preview_data['permits'] = $permits?implode('、', $permits):'（无）';
        //订单相关信息
        $order_goods_info = array();
        $order_goods_info['goods_id'] = $guide_data['packgoodsid'];
        $order_goods_info['is_package'] = '1';//是否是套餐
        $order_goods_info['type'] = 1;//1.企业设立 2.企业变更
        $order_goods_info['is_jinchukou'] = $guide_data['jinchukou'];
        $order_goods_info['permit'] = $permits;
        session('order_goods',$order_goods_info);
        
        $this->assign($preview_data);
        $this->display('setform_order_data');
    }
    
    public function changeData(){
        $goods_ids = I('post.cgoodsadd');
        if(!empty($goods_ids)){
            $goods_idstr = implode(',', $goods_ids);
            $goods = D('Goods')->field('goods_id,goods_name,goods_brief')->where("goods_id in($goods_idstr)")->select();
            $this->assign('goods',$goods);
        }
        
        $datas = session('guide_data');
        $datas['company_type'] = $datas['firmprtype'] == '0'?'内资公司':'外资公司';
        //订单相关信息
        $order_data_info = array();
        $order_data_info['goods_id'] = 10;
        $order_data_info['is_package'] = 1;
        $order_data_info['type'] = 2;//1.企业设立 2.企业变更
        $order_data_info['firmprtype'] = $datas['firmprtype'];
        $order_data_info['extra_goods'] = $goods_ids;
        session('order_goods',$order_data_info);
        
        $this->assign('datas',$datas);
        $this->display('chgform_order_data');
    }
    
    public function getAddress() {
        $this->success(D('Goods')->where(array('is_flow_type'=>'3','is_alone_sale'=>'1','is_delete'=>'0'))->getField('goods_name'));
    }
    
}